package com.century.sjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.android.volley.RequestQueue;
import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.util.Constant;


/**
 * Created by luodong on 16-05-25.
 */
public class QualificationAdapter extends BaseAdapter {

    private LayoutInflater mLayoutInflater;
    private String[] imageUrls;
    private Context context;
    private String aCiry;
    private RequestQueue mQueue;

    //初始化
    public QualificationAdapter(Context context, String[] imageUrls, RequestQueue mQueue) {
        this.imageUrls = imageUrls;
        this.context = context;
        mLayoutInflater = LayoutInflater.from(context);
        this.mQueue=mQueue;
    }

    @Override
    public int getCount() {
        return imageUrls.length;
    }

    @Override
    public Object getItem(int i) {
        return imageUrls[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup viewGroup) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.sjt_commodity_item, null);
            holder.nivImage = (ImageView) convertView.findViewById(R.id.niv_image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(Constant.BaseWebHost + imageUrls[i]).into(holder.nivImage);
//        holder.nivImage.setErrorImageResId(R.mipmap.picture_defualt);
//        holder.nivImage.setDefaultImageResId(R.mipmap.picture_defualt);
//        LruImageCache lruImageCache = LruImageCache.instance();
//        ImageLoader mImageLoader = new ImageLoader(mQueue, lruImageCache);
//        holder.nivImage.setImageUrl(Constant.BaseWebHost+imageUrls[i], mImageLoader);

        return convertView;

    }

    class ViewHolder {

        public ImageView nivImage;

    }
}
